new Vue({
  el: '#recruit',
  components: {},
  data: {
    isShow1: false,
    positions: [],
    morePositions: [],
    isShow: true,
    provide: [
      '良好的工作环境',
      '丰厚的薪酬回报',
      '完善的社会保险',
      '定期开展培训课程',
      '丰富的生日及节日礼品',
      '更好发展平台',
    ],
    screenWidth: 1, //屏幕宽
  },
  mounted() {
    var that = this;
    that.screenWidth = document.body.clientWidth;
    axios.get('http://dl.sword.ink:2334/recruit').then((response) => {
      var listData = JSON.parse(JSON.stringify(response.data.data));
      // console.log(listData);
      var i;
      for (i = 0; i < listData.length; i++) {
        if (listData[i].releaseTime != undefined)
          listData[i].releaseTime = listData[i].releaseTime.substring(0, 10); //.replaceAll("-","/");
      }
      // console.log(listData);
      this.morePositions = listData;
      var list = JSON.parse(JSON.stringify(listData));
      //把这个数组this.morePositions先变成字符串再变成对象
      list.splice(6, list.length - 6); //从下标为6的数据开始删除list.length-6个
      this.positions = list; //再把这个list赋值给少的
      for (i = 0; i < this.positions.length; i++) {
        this.positions[i].yes = 'visibility:visible';
      }
    });
    window.onresize = () => {
      return (() => {
        // console.log(this.positions.length);
        that.screenWidth = document.body.clientWidth;
        if (!that.isShow) {
          if (that.screenWidth >= 1254) {
            that.positions = JSON.parse(JSON.stringify(that.morePositions));
            // console.log(that.positions.length);
            if (that.positions.length % 2 == 1) {
              that.positions[that.positions.length] = {};
              that.positions[that.positions.length - 1].yes =
                'visibility:hidden';
            }
          } else {
            that.positions = JSON.parse(JSON.stringify(that.morePositions));
          }
        }
      })();
    };
    window.addEventListener('scroll', this.windowScroll);
  },
  methods: {
    windowScroll() {
      let scrollTop =
        window.pageYOffset ||
        document.documentElement.scrollTop ||
        document.body.scrollTop;
      this.opacity = Math.abs(Math.round(scrollTop)) / 100;
      if (this.opacity >= 1) {
        this.isShow1 = true;
      }
    },
    getHref(id, index) {
      // var a = document.getElementById(index);
      // a.setAttribute('href', './position.html?id=' + id);
      var x = '#recruit a[' + 'id =' + index + ']';
      var a = $(x);
      // console.log(a)
      a[0].setAttribute('href', './position.html?id=' + id);
      // var  x  =  'a['  +  'id ='  +  index  +  ']';
      // var  a  =  $(x);
      // console.log(a)
      // a[0].setAttribute('href',  './position.html?id='  +  id);
    },
    Change() {
      this.isShow = !this.isShow;
      // console.log(this.screenWidth);
      this.positions = JSON.parse(JSON.stringify(this.morePositions));
      if (this.screenWidth >= 1254 && this.positions.length % 2 == 1) {
        // console.log("haha");
        this.positions[this.positions.length] = {};
        this.positions[this.positions.length - 1].yes = 'visibility:hidden';
      }
    },
  },
});
